public class SyncBlock implements Runnable{

    private int count = 5;

    public void run(){
 
        for(int i = 0; i < 5; i++){
            // sync block
            synchronized(this){
                if(count > 0){
                    try{
                        Thread.sleep(1000);
                    }catch(Exception e){
                        e.printStackTrace();
                    }

                    System.out.println(Thread.currentThread().getName() + " : " + count--);
                }
            }
        }

    }

    public static void main(String[] args){

        SyncBlock syncb = new SyncBlock();
        Thread t1 = new Thread(syncb);
        Thread t2 = new Thread(syncb);
        Thread t3 = new Thread(syncb);

        t1.start();
        t2.start();
        t3.start();

    }

}